package com.unf.edu.rms.controller.thesis;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Date;
import java.util.LinkedList;

import java.text.SimpleDateFormat;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.unf.edu.rms.controller.userlogin.UserLoginController;
import com.unf.edu.rms.controller.users.RMSBaseController;
import com.unf.edu.rms.dao.Category;
import com.unf.edu.rms.dao.Faculty;
import com.unf.edu.rms.dao.Student;
import com.unf.edu.rms.dao.Thesis;
import com.unf.edu.rms.dao.ThesisCommittee;
import com.unf.edu.rms.dao.ThesisStatus;
import com.unf.edu.rms.dao.ThesisToThesisStatus;
import com.unf.edu.rms.service.CategoryService;
import com.unf.edu.rms.service.FacultyService;
import com.unf.edu.rms.service.StudentService;
import com.unf.edu.rms.service.ThesisService;
import com.unf.edu.rms.util.DateUtil;
import com.unf.edu.rms.util.RMSConstants;

@Controller
public class ThesisController extends RMSBaseController{
	
	@Autowired
	private ThesisService thesisService;
	
	@Autowired
	private CategoryService categoryService;
	
	@Autowired
	private StudentService studentService;
	
	@Autowired
	private FacultyService facultyService;
	
	@Autowired
	private UserLoginController userLoginController;
	
	@RequestMapping("/viewThesisList")
	public String viewThesisList(Model model) {
		System.out.println("ThesisController.viewThesisList()==========");
		List<Thesis> thesisList = thesisService.getThesisList();
		String thesisStatusOverviewString = "";
		for(Thesis t:thesisList){
			Set<ThesisCommittee> thesisCommittees = t.getThesisCommittees();
			for(ThesisCommittee committee:thesisCommittees)
			{
				t.setThesisChairId(Integer.toString(committee.getFacultyByCommitteeChair().getFacultyId()));
				t.setThesisChairName(committee.getFacultyByCommitteeChair().getFullName());
				t.setThesisChairFirstName(committee.getFacultyByCommitteeChair().getFirstName());
				t.setThesisChairLastName(committee.getFacultyByCommitteeChair().getLastName());
			}
			
			Set<ThesisToThesisStatus> thesisToThesisStatuses = t.getThesisToThesisStatuses();
			System.out.println("ThesisController.viewThesisList()======thesis Id======"+t.getThesisId());
			for(ThesisToThesisStatus status:thesisToThesisStatuses)
			{
				if(status.getThesisStatus().getEnrolled().charAt(0)=='Y' || status.getThesisStatus().getEnrolled().charAt(0)=='y'){
					thesisStatusOverviewString = "Enrolled in Thesis";
					t.setEnrolledDateStr(status.getThesisStatus().getEnrolledDate()!=null?status.getThesisStatus().getEnrolledDate().toString():null);
				}
				if(status.getThesisStatus().getProspectusPassed().charAt(0)=='Y' || status.getThesisStatus().getProspectusPassed().charAt(0)=='y')
				{
					thesisStatusOverviewString = ("Prospectus completed");
					t.setProspectusDateStr(status.getThesisStatus().getProspectusDate()!=null?status.getThesisStatus().getProspectusDate().toString():null);
				}
				if(status.getThesisStatus().getDefensePassed().charAt(0)=='Y'||status.getThesisStatus().getDefensePassed().charAt(0)=='y')
				{
					thesisStatusOverviewString = ("Defense completed");
					t.setDefenseDateStr(status.getThesisStatus().getDefenseDate()!=null?status.getThesisStatus().getDefenseDate().toString():null);
				}
				if(status.getThesisStatus().getSubmittedDirector().charAt(0)=='Y' || status.getThesisStatus().getSubmittedDirector().charAt(0)=='y')
				{
					thesisStatusOverviewString = ("Submitted to SoC Director");
					t.setSubDirDateStr(status.getThesisStatus().getSubmittedDirectorDate()!=null?status.getThesisStatus().getSubmittedDirectorDate().toString():null);
					if(status.getThesisStatus().getAcceptedDirectorDate() != null){
						thesisStatusOverviewString = ("Accepted by SoC Director");
						t.setAcpDirDateStr(status.getThesisStatus().getAcceptedDirectorDate().toString());
					}
				}
				if(status.getThesisStatus().getSubmittedDean().charAt(0)=='Y' || status.getThesisStatus().getSubmittedDean().charAt(0)=='y')
				{
					thesisStatusOverviewString = ("Submitted to CCEC Dean");
					if(status.getThesisStatus().getAcceptedDeanDate() != null){
						thesisStatusOverviewString = ("Accepted by CCEC Dean");
						t.setAcpDeanDateStr(status.getThesisStatus().getAcceptedDeanDate().toString());
					}
					
				}
				if(status.getThesisStatus().getSubmittedGradDean().charAt(0)=='Y' || status.getThesisStatus().getSubmittedGradDean().charAt(0)=='y')
				{
					thesisStatusOverviewString = ("Submitted to Graduate Dean");
					if(status.getThesisStatus().getAcceptedGradDeanDate() != null){
						thesisStatusOverviewString = ("Accepted by Graduate Dean Director");
						t.setAcpGradDeanDateStr(status.getThesisStatus().getAcceptedGradDeanDate().toString());
					}
				}
				if(status.getThesisStatus().getSubmittedLibrary().charAt(0)=='Y' || status.getThesisStatus().getSubmittedLibrary().charAt(0)=='y')
				{
					thesisStatusOverviewString = ("Submitted to SoC Library");
					if(status.getThesisStatus().getAcceptedLibraryDate() != null){
						thesisStatusOverviewString = ("Accepted by SoC Library");
						t.setAcpLibraryDateStr(status.getThesisStatus().getAcceptedLibraryDate().toString());
					}
				}
			}
			t.setThesisStatusOverviewString(thesisStatusOverviewString);
		}
		model.addAttribute("thesisStatusOverviewString",thesisStatusOverviewString);
		model.addAttribute("thesisList", thesisList);
		return RMSConstants.THESIS_LIST_VIEW;
		
	}
	
	@RequestMapping("/printThesisList")
	public String printThesisList(Model model) {
		System.out.println("ThesisController.viewThesisList()==========");
		List<Thesis> thesisList = thesisService.getThesisList();
		String thesisStatusOverviewString = "";
		for(Thesis t:thesisList){
			Set<ThesisCommittee> thesisCommittees = t.getThesisCommittees();
			for(ThesisCommittee committee:thesisCommittees)
			{
				t.setThesisChairId(Integer.toString(committee.getFacultyByCommitteeChair().getFacultyId()));
				t.setThesisChairName(committee.getFacultyByCommitteeChair().getFullName());
				t.setThesisChairFirstName(committee.getFacultyByCommitteeChair().getFirstName());
				t.setThesisChairLastName(committee.getFacultyByCommitteeChair().getLastName());
			}
			
			Set<ThesisToThesisStatus> thesisToThesisStatuses = t.getThesisToThesisStatuses();
			System.out.println("ThesisController.viewThesisList()======thesis Id======"+t.getThesisId());
			for(ThesisToThesisStatus status:thesisToThesisStatuses)
			{
				if(status.getThesisStatus().getEnrolled().charAt(0)=='Y' || status.getThesisStatus().getEnrolled().charAt(0)=='y'){
					thesisStatusOverviewString = "Enrolled in Thesis";
					t.setEnrolledDateStr(status.getThesisStatus().getEnrolledDate()!=null?status.getThesisStatus().getEnrolledDate().toString():null);
				}
				if(status.getThesisStatus().getProspectusPassed().charAt(0)=='Y' || status.getThesisStatus().getProspectusPassed().charAt(0)=='y')
				{
					thesisStatusOverviewString = ("Prospectus completed");
					t.setProspectusDateStr(status.getThesisStatus().getProspectusDate()!=null?status.getThesisStatus().getProspectusDate().toString():null);
				}
				if(status.getThesisStatus().getDefensePassed().charAt(0)=='Y'||status.getThesisStatus().getDefensePassed().charAt(0)=='y')
				{
					thesisStatusOverviewString = ("Defense completed");
					t.setDefenseDateStr(status.getThesisStatus().getDefenseDate()!=null?status.getThesisStatus().getDefenseDate().toString():null);
				}
				if(status.getThesisStatus().getSubmittedDirector().charAt(0)=='Y' || status.getThesisStatus().getSubmittedDirector().charAt(0)=='y')
				{
					thesisStatusOverviewString = ("Submitted to SoC Director");
					t.setSubDirDateStr(status.getThesisStatus().getSubmittedDirectorDate()!=null?status.getThesisStatus().getSubmittedDirectorDate().toString():null);
					if(status.getThesisStatus().getAcceptedDirectorDate() != null){
						thesisStatusOverviewString = ("Accepted by SoC Director");
						t.setAcpDirDateStr(status.getThesisStatus().getAcceptedDirectorDate().toString());
					}
				}
				if(status.getThesisStatus().getSubmittedDean().charAt(0)=='Y' || status.getThesisStatus().getSubmittedDean().charAt(0)=='y')
				{
					thesisStatusOverviewString = ("Submitted to CCEC Dean");
					if(status.getThesisStatus().getAcceptedDeanDate() != null){
						thesisStatusOverviewString = ("Accepted by CCEC Dean");
						t.setAcpDeanDateStr(status.getThesisStatus().getAcceptedDeanDate().toString());
					}
					
				}
				if(status.getThesisStatus().getSubmittedGradDean().charAt(0)=='Y' || status.getThesisStatus().getSubmittedGradDean().charAt(0)=='y')
				{
					thesisStatusOverviewString = ("Submitted to Graduate Dean");
					if(status.getThesisStatus().getAcceptedGradDeanDate() != null){
						thesisStatusOverviewString = ("Accepted by Graduate Dean Director");
						t.setAcpGradDeanDateStr(status.getThesisStatus().getAcceptedGradDeanDate().toString());
					}
				}
				if(status.getThesisStatus().getSubmittedLibrary().charAt(0)=='Y' || status.getThesisStatus().getSubmittedLibrary().charAt(0)=='y')
				{
					thesisStatusOverviewString = ("Submitted to SoC Library");
					if(status.getThesisStatus().getAcceptedLibraryDate() != null){
						thesisStatusOverviewString = ("Accepted by SoC Library");
						t.setAcpLibraryDateStr(status.getThesisStatus().getAcceptedLibraryDate().toString());
					}
				}
			}
			t.setThesisStatusOverviewString(thesisStatusOverviewString);
		}
		model.addAttribute("thesisStatusOverviewString",thesisStatusOverviewString);
		model.addAttribute("thesisList", thesisList);
		return RMSConstants.THESIS_LIST_PRINT;
		
	}
	
	@RequestMapping(value = "/viewNewThesis", method = RequestMethod.POST)
	public String viewNewThesis(@ModelAttribute("thesis") Thesis thesis,Model model) {
		if(userLoginController.checkValidateSession()==0){
			return "redirect:Dashboard.html";
		}
		List<Category> categoryList = categoryService.viewCategoryTable();
		List<Faculty> facultyList = facultyService.getFacultyList();
		List<Thesis> thesisList = thesisService.getThesisList();
		model.addAttribute("categoryList", categoryList);
		model.addAttribute("facultyList",facultyList);
		model.addAttribute("thesisList", thesisList);
		List<Student> studentList = studentService.viewStudentTable();
		Map<Integer,String> studentMap = new HashMap<Integer, String>();
		Map<Integer,String> idMap = new HashMap<Integer, String>();
		for(Student student:studentList)
		{
			studentMap.put(student.getStudentId(),student.getFullName());
//			idMap.put(student.getStudentId(), student.getStudentId().toString());
		}
		for(Thesis thesisx:thesisList){
			idMap.put(thesisx.getThesisId(), thesisx.getStudent().getStudentId().toString());
		}
		model.addAttribute("studentList", studentMap);
		model.addAttribute("idMap", idMap);
		return RMSConstants.ADD_THESIS_VIEW;
	}
        
    
	@RequestMapping(value = "/addNewThesis", method = RequestMethod.POST)
	public String addNewThesis(@ModelAttribute("thesis") Thesis thesis,BindingResult bindingResult,Model model) {
		Category category = new Category();
		category.setCategoryId(new Integer(thesis.getCategoryStr()));
		thesis.setCategory(category);
		
		//Enrolled Date
		if(null!=thesis.getEnrolledDateStr()&&thesis.getEnrolledDateStr().length() > 0)
			thesis.setEnrolledDate(DateUtil.strToDate(thesis.getEnrolledDateStr()));
		//Prospectus Date
		if(null!=thesis.getProspectusDateStr()&&thesis.getProspectusDateStr().length()>0)
			thesis.setProspectusDate(DateUtil.strToDate(thesis.getProspectusDateStr()));
		//Defense Date
		if(null!=thesis.getDefenseDateStr()&&thesis.getDefenseDateStr().length()>0)
			thesis.setDefenseDate(DateUtil.strToDate(thesis.getDefenseDateStr()));
		//Submitted SoC Date
		if(null!=thesis.getSubSoCDateStr()&&thesis.getSubSoCDateStr().length()>0)
			thesis.setSubmittedSoCdate(DateUtil.strToDate(thesis.getSubSoCDateStr()));
		//Accepted SoC Date
		if(null!=thesis.getAcpSoCDateStr()&&thesis.getAcpSoCDateStr().length()>0)
			thesis.setAcceptedSoCdate(DateUtil.strToDate(thesis.getAcpSoCDateStr()));
		//Submitted Director Date
		if(null!=thesis.getSubDirDateStr() && thesis.getSubDirDateStr().length()>0)
			thesis.setSubmittedDirectorDate(DateUtil.strToDate(thesis.getSubDirDateStr()));
		//Accepted Director Date
		if(null!=thesis.getAcpDirDateStr() && thesis.getAcpDirDateStr().length() > 0)
			thesis.setAcceptedDirectorDate(DateUtil.strToDate(thesis.getAcpDirDateStr()));
		//Submitted Dean Date
		if(null!=thesis.getSubDeanDateStr()&&thesis.getSubDeanDateStr().length() > 0)
			thesis.setSubmittedDeanDate(DateUtil.strToDate(thesis.getSubDeanDateStr()));
		//Accept Dean Date
		if(null!=thesis.getAcpDeanDateStr()&&thesis.getAcpDeanDateStr().length() > 0)
			thesis.setAcceptedDeanDate(DateUtil.strToDate(thesis.getAcpDeanDateStr()));
		//Submitted Grad Dean Date
		if(null!=thesis.getSubGradDeanDateStr()&&thesis.getSubGradDeanDateStr().length() > 0)
			thesis.setSubmittedGradDeanDate(DateUtil.strToDate(thesis.getSubGradDeanDateStr()));
		//Accepted Grad Dean Date
		if(null!=thesis.getAcpGradDeanDateStr()&&thesis.getAcpGradDeanDateStr().length() > 0)
			thesis.setAcceptedGradDeanDate(DateUtil.strToDate(thesis.getAcpGradDeanDateStr()));
		//Submitted Library Date
		if(null!=thesis.getSubLibraryDateStr()&&thesis.getSubLibraryDateStr().length() > 0)
			thesis.setSubmittedLibraryDate(DateUtil.strToDate(thesis.getSubLibraryDateStr()));
		//Accepted Library Date
		if(null!=thesis.getAcpLibraryDateStr()&&thesis.getAcpLibraryDateStr().length() > 0)
			thesis.setAcceptedLibraryDate(DateUtil.strToDate(thesis.getAcpLibraryDateStr()));
		
		System.out.println("ThesisController.addNewThesis()============"+thesis);
		thesis.setThesisDoi(thesis.getThesisDoi());
		populateThesisData(thesis);
		thesisService.addNewThesis(thesis);
		return "redirect:viewThesisList.html";
	}
	
	@RequestMapping(value = "/viewThesisDetails", method = RequestMethod.POST)
    public String viewThesisDetails(@RequestParam(required=true) int thesisId, Model model){
        Thesis thesis = thesisService.getThesisById(thesisId);//Add parameters to relevant methods?
        
    	Set<ThesisToThesisStatus> thesisToThesisStatuses = thesis.getThesisToThesisStatuses();
    	
    	LinkedList<String> thesisStatusOverview = new LinkedList<String>();
    	LinkedList<Date> thesisStatusOverviewDates = new LinkedList<Date>();
    	LinkedList<Milestone> milestones = new LinkedList<Milestone>();
    	
    	Set<ThesisCommittee> thesisCommittees = thesis.getThesisCommittees();
    	for(ThesisCommittee committee:thesisCommittees)
    	{
    		thesis.setThesisChairName(committee.getFacultyByCommitteeChair().getFullName());
    		thesis.setCommitteeMember1Name(committee.getFacultyByCommitteeMember1()!=null?committee.getFacultyByCommitteeMember1().getFullName():"");
    		thesis.setCommitteeMember2Name(committee.getFacultyByCommitteeMember2()!=null?committee.getFacultyByCommitteeMember2().getFullName():"");
    		thesis.setCommitteeMember3Name(committee.getFacultyByCommitteeMember3()!=null?committee.getFacultyByCommitteeMember3().getFullName():"");
    		thesis.setCommitteeMember4Name(committee.getFacultyByCommitteeMember4()!=null?committee.getFacultyByCommitteeMember4().getFullName():"");
    	}
    	
		for(ThesisToThesisStatus status:thesisToThesisStatuses)
		{
			if(status.getThesisStatus().getEnrolled().charAt(0)=='Y' || status.getThesisStatus().getEnrolled().charAt(0)=='y'){
				thesisStatusOverview.add("Enrolled in Thesis");
				Milestone milestone = new Milestone("Enrolled in Thesis");
				if(status.getThesisStatus().getEnrolledDate() != null){
					Date enrolledDate = status.getThesisStatus().getEnrolledDate();
					milestone.setDate(enrolledDate);
					
					thesisStatusOverviewDates.add(enrolledDate);
				}
				milestones.add(milestone);
				//String eD = (new SimpleDateFormat("MM-dd-yyyy").format(enrolledDate));
				//thesisStatusOverview.add(eD);
			}
			if(status.getThesisStatus().getProspectusPassed().charAt(0)=='Y' || status.getThesisStatus().getProspectusPassed().charAt(0)=='y')
			{
				thesisStatusOverview.add("Prospectus completed");
				Milestone milestone = new Milestone("Prospectus Completed");
				if(status.getThesisStatus().getProspectusDate() != null){
					Date prospectusDate = status.getThesisStatus().getProspectusDate();
					milestone.setDate(prospectusDate);
					
					thesisStatusOverviewDates.add(prospectusDate);
				}
				milestones.add(milestone);
			}
			if(status.getThesisStatus().getDefensePassed().charAt(0)=='Y'||status.getThesisStatus().getDefensePassed().charAt(0)=='y')
			{
				thesisStatusOverview.add("Defense completed");
				Milestone milestone = new Milestone("Defense Completed");
				if(status.getThesisStatus().getDefenseDate() != null){
					Date defenseDate = status.getThesisStatus().getDefenseDate();
					milestone.setDate(defenseDate);
					
					thesisStatusOverviewDates.add(defenseDate);
				}
				milestones.add(milestone);
			}
			if(status.getThesisStatus().getSubmittedDirector().charAt(0)=='Y' || status.getThesisStatus().getSubmittedDirector().charAt(0)=='y')
			{
				thesisStatusOverview.add("Submitted to School of Computing Director");
				Milestone milestone = new Milestone("Submitted to School of Computing Director");
				if(status.getThesisStatus().getSubmittedDirectorDate() != null){
					Date subDirDate = status.getThesisStatus().getSubmittedDirectorDate();
					milestone.setDate(subDirDate);
					
					thesisStatusOverviewDates.add(subDirDate);
				}
				milestones.add(milestone);
				if(status.getThesisStatus().getAcceptedDirectorDate() != null){
					thesisStatusOverview.add("Accepted by School of Computing Director");
					Date acpDirDate = status.getThesisStatus().getAcceptedDirectorDate();
					Milestone milestoneB = new Milestone("Accepted by School of Computing Director", acpDirDate);
					milestones.add(milestoneB);
					thesisStatusOverviewDates.add(acpDirDate);
				}
			}
			if(status.getThesisStatus().getSubmittedDean().charAt(0)=='Y' || status.getThesisStatus().getSubmittedDean().charAt(0)=='y')
			{
				thesisStatusOverview.add("Submitted to the CCEC Dean");
				Milestone milestone = new Milestone("Submitted to the CCEC Dean");
				if(status.getThesisStatus().getSubmittedDeanDate() != null){
					Date subDeanDate = status.getThesisStatus().getSubmittedDeanDate();
					milestone.setDate(subDeanDate);
					
					thesisStatusOverviewDates.add(subDeanDate);
				}
				milestones.add(milestone);
				if(status.getThesisStatus().getAcceptedDeanDate() != null){
					thesisStatusOverview.add("Accepted by the CCEC Dean");
					Date acpDeanDate = status.getThesisStatus().getAcceptedDeanDate();
					Milestone milestoneB = new Milestone("Accepted by the CCEC Dean", acpDeanDate);
					milestones.add(milestoneB);
					thesisStatusOverviewDates.add(acpDeanDate);
				}
			}
			if(status.getThesisStatus().getSubmittedGradDean().charAt(0)=='Y' || status.getThesisStatus().getSubmittedGradDean().charAt(0)=='y')
			{
				thesisStatusOverview.add("Submitted to the Graduate Dean");
				Milestone milestone = new Milestone("Submitted to the Graduate Dean");
				if(status.getThesisStatus().getSubmittedGradDeanDate() != null){
					Date subGradDeanDate = status.getThesisStatus().getSubmittedGradDeanDate();
					milestone.setDate(subGradDeanDate);
					
					thesisStatusOverviewDates.add(subGradDeanDate);
				}
				milestones.add(milestone);
				if(status.getThesisStatus().getAcceptedGradDeanDate() != null){
					thesisStatusOverview.add("Accepted by the Graduate Dean");
					Date acpGradDeanDate = status.getThesisStatus().getAcceptedGradDeanDate();
					Milestone milestoneB = new Milestone("Accepted by the Graduate Dean", acpGradDeanDate);
					milestones.add(milestoneB);
					thesisStatusOverviewDates.add(acpGradDeanDate);
				}
			}
			if(status.getThesisStatus().getSubmittedLibrary().charAt(0)=='Y' || status.getThesisStatus().getSubmittedLibrary().charAt(0)=='y')
			{
				thesisStatusOverview.add("Submitted to the School of Computing Library");
				Milestone milestone = new Milestone("Submitted to the School of Computing Library");
				if(status.getThesisStatus().getSubmittedLibrary() != null){
					Date subLibDate = status.getThesisStatus().getSubmittedLibraryDate();
					milestone.setDate(subLibDate);
					
					thesisStatusOverviewDates.add(subLibDate);
				}
				milestones.add(milestone);
				if(status.getThesisStatus().getAcceptedLibraryDate() != null){
					thesisStatusOverview.add("Accepted by the School of Computing Library");
					Date acpLibDate = status.getThesisStatus().getAcceptedLibraryDate();
					Milestone milestoneB = new Milestone("Accepted by the School of Computing Library", acpLibDate);
					milestones.add(milestoneB);
					thesisStatusOverviewDates.add(acpLibDate);
				}
			}
		}
		thesis.setThesisStatusOverview(thesisStatusOverview);
    	thesis.setThesisStatusOverviewDates(thesisStatusOverviewDates);
    	thesis.setMilestoneOverview(milestones);
        model.addAttribute("thesis",thesis);
        return RMSConstants.THESIS_DETAILS_VIEW;
    }
	
	@RequestMapping(value = "/printThesisDetails", method = RequestMethod.POST)
    public String printThesisDetails(@RequestParam(required=true) int thesisId, Model model){
        Thesis thesis = thesisService.getThesisById(thesisId);//Add parameters to relevant methods?
       
        Set<ThesisCommittee> thesisCommittees = thesis.getThesisCommittees();
    	for(ThesisCommittee committee:thesisCommittees)
    	{
    		thesis.setThesisChairName(committee.getFacultyByCommitteeChair().getFullName());
    		thesis.setCommitteeMember1Name(committee.getFacultyByCommitteeMember1()!=null?committee.getFacultyByCommitteeMember1().getFullName():"");
    		thesis.setCommitteeMember2Name(committee.getFacultyByCommitteeMember2()!=null?committee.getFacultyByCommitteeMember2().getFullName():"");
    		thesis.setCommitteeMember3Name(committee.getFacultyByCommitteeMember3()!=null?committee.getFacultyByCommitteeMember3().getFullName():"");
    		thesis.setCommitteeMember4Name(committee.getFacultyByCommitteeMember4()!=null?committee.getFacultyByCommitteeMember4().getFullName():"");
    	}
    	
    	Set<ThesisToThesisStatus> thesisToThesisStatuses = thesis.getThesisToThesisStatuses();
    	LinkedList<String> thesisStatusOverview = new LinkedList<String>();
    	LinkedList<Date> thesisStatusOverviewDates = new LinkedList<Date>();
    	LinkedList<Milestone> milestones = new LinkedList<Milestone>();
		for(ThesisToThesisStatus status:thesisToThesisStatuses)
		{
			if(status.getThesisStatus().getEnrolled().charAt(0)=='Y' || status.getThesisStatus().getEnrolled().charAt(0)=='y'){
				thesisStatusOverview.add("Enrolled in Thesis");
				Milestone milestone = new Milestone("Enrolled in Thesis");
				if(status.getThesisStatus().getEnrolledDate() != null){
					Date enrolledDate = status.getThesisStatus().getEnrolledDate();
					milestone.setDate(enrolledDate);
					
					thesisStatusOverviewDates.add(enrolledDate);
				}
				milestones.add(milestone);
				//String eD = (new SimpleDateFormat("MM-dd-yyyy").format(enrolledDate));
				//thesisStatusOverview.add(eD);
			}
			if(status.getThesisStatus().getProspectusPassed().charAt(0)=='Y' || status.getThesisStatus().getProspectusPassed().charAt(0)=='y')
			{
				thesisStatusOverview.add("Prospectus completed");
				Milestone milestone = new Milestone("Prospectus Completed");
				if(status.getThesisStatus().getProspectusDate() != null){
					Date prospectusDate = status.getThesisStatus().getProspectusDate();
					milestone.setDate(prospectusDate);
					
					thesisStatusOverviewDates.add(prospectusDate);
				}
				milestones.add(milestone);
			}
			if(status.getThesisStatus().getDefensePassed().charAt(0)=='Y'||status.getThesisStatus().getDefensePassed().charAt(0)=='y')
			{
				thesisStatusOverview.add("Defense completed");
				Milestone milestone = new Milestone("Defense Completed");
				if(status.getThesisStatus().getDefenseDate() != null){
					Date defenseDate = status.getThesisStatus().getDefenseDate();
					milestone.setDate(defenseDate);
					
					thesisStatusOverviewDates.add(defenseDate);
				}
				milestones.add(milestone);
			}
			if(status.getThesisStatus().getSubmittedDirector().charAt(0)=='Y' || status.getThesisStatus().getSubmittedDirector().charAt(0)=='y')
			{
				thesisStatusOverview.add("Submitted to School of Computing Director");
				Milestone milestone = new Milestone("Submitted to School of Computing Director");
				if(status.getThesisStatus().getSubmittedDirectorDate() != null){
					Date subDirDate = status.getThesisStatus().getSubmittedDirectorDate();
					milestone.setDate(subDirDate);
					
					thesisStatusOverviewDates.add(subDirDate);
				}
				milestones.add(milestone);
				if(status.getThesisStatus().getAcceptedDirectorDate() != null){
					thesisStatusOverview.add("Accepted by School of Computing Director");
					Date acpDirDate = status.getThesisStatus().getAcceptedDirectorDate();
					Milestone milestoneB = new Milestone("Accepted by School of Computing Director", acpDirDate);
					milestones.add(milestoneB);
					thesisStatusOverviewDates.add(acpDirDate);
				}
			}
			if(status.getThesisStatus().getSubmittedDean().charAt(0)=='Y' || status.getThesisStatus().getSubmittedDean().charAt(0)=='y')
			{
				thesisStatusOverview.add("Submitted to the CCEC Dean");
				Milestone milestone = new Milestone("Submitted to the CCEC Dean");
				if(status.getThesisStatus().getSubmittedDeanDate() != null){
					Date subDeanDate = status.getThesisStatus().getSubmittedDeanDate();
					milestone.setDate(subDeanDate);
					
					thesisStatusOverviewDates.add(subDeanDate);
				}
				milestones.add(milestone);
				if(status.getThesisStatus().getAcceptedDeanDate() != null){
					thesisStatusOverview.add("Accepted by the CCEC Dean");
					Date acpDeanDate = status.getThesisStatus().getAcceptedDeanDate();
					Milestone milestoneB = new Milestone("Accepted by the CCEC Dean", acpDeanDate);
					milestones.add(milestoneB);
					thesisStatusOverviewDates.add(acpDeanDate);
				}
			}
			if(status.getThesisStatus().getSubmittedGradDean().charAt(0)=='Y' || status.getThesisStatus().getSubmittedGradDean().charAt(0)=='y')
			{
				thesisStatusOverview.add("Submitted to the Graduate Dean");
				Milestone milestone = new Milestone("Submitted to the Graduate Dean");
				if(status.getThesisStatus().getSubmittedGradDeanDate() != null){
					Date subGradDeanDate = status.getThesisStatus().getSubmittedGradDeanDate();
					milestone.setDate(subGradDeanDate);
					
					thesisStatusOverviewDates.add(subGradDeanDate);
				}
				milestones.add(milestone);
				if(status.getThesisStatus().getAcceptedGradDeanDate() != null){
					thesisStatusOverview.add("Accepted by the Graduate Dean");
					Date acpGradDeanDate = status.getThesisStatus().getAcceptedGradDeanDate();
					Milestone milestoneB = new Milestone("Accepted by the Graduate Dean", acpGradDeanDate);
					milestones.add(milestoneB);
					thesisStatusOverviewDates.add(acpGradDeanDate);
				}
			}
			if(status.getThesisStatus().getSubmittedLibrary().charAt(0)=='Y' || status.getThesisStatus().getSubmittedLibrary().charAt(0)=='y')
			{
				thesisStatusOverview.add("Submitted to the School of Computing Library");
				Milestone milestone = new Milestone("Submitted to the School of Computing Library");
				if(status.getThesisStatus().getSubmittedLibrary() != null){
					Date subLibDate = status.getThesisStatus().getSubmittedLibraryDate();
					milestone.setDate(subLibDate);
					
					thesisStatusOverviewDates.add(subLibDate);
				}
				milestones.add(milestone);
				if(status.getThesisStatus().getAcceptedLibraryDate() != null){
					thesisStatusOverview.add("Accepted by the School of Computing Library");
					Date acpLibDate = status.getThesisStatus().getAcceptedLibraryDate();
					Milestone milestoneB = new Milestone("Accepted by the School of Computing Library", acpLibDate);
					milestones.add(milestoneB);
					thesisStatusOverviewDates.add(acpLibDate);
				}
			}
		
		}
		thesis.setThesisStatusOverview(thesisStatusOverview);
		thesis.setThesisStatusOverviewDates(thesisStatusOverviewDates);
    	thesis.setMilestoneOverview(milestones);
        model.addAttribute("thesis",thesis);
        return RMSConstants.THESIS_DETAILS_PRINT;
    }
    
    @RequestMapping(value = "/viewExistingThesis", method = RequestMethod.POST)
	public String viewExitingThesis(@RequestParam(required=true) int thesisId,Model model) {
    	if(userLoginController.checkValidateSession()==0){
			return "redirect:Dashboard.html";
		}
    	Thesis thesis = thesisService.getThesisById(thesisId);//Add parameters to relevant methods?
    	model.addAttribute("categoryList",categoryService.viewCategoryTable());
		model.addAttribute("facultyList",facultyService.getFacultyList());
		
		thesis.setStudentFullName(thesis.getStudent().getFullName());
		
		List<Student> studentList = studentService.viewStudentTable();
		Map<Integer,String> studentMap = new HashMap<Integer, String>();
		for(Student student:studentList)
		{
			studentMap.put(student.getStudentId(),student.getFullName());
		}
		
        Set<ThesisCommittee> thesisCommittees = thesis.getThesisCommittees();
        
    	for(ThesisCommittee thesisCommittee:thesisCommittees){
    		
    		if(thesisCommittee.getFacultyByCommitteeChair()!=null){
        		thesis.setThesisChairId(Integer.toString(thesisCommittee.getFacultyByCommitteeChair().getFacultyId()));
        		thesis.setThesisChairName(thesisCommittee.getFacultyByCommitteeChair().getFullName());
    		}
    		
    		if(thesisCommittee.getFacultyByCommitteeMember1()!=null){
    			thesis.setCommitteeMember1Id(Integer.toString(thesisCommittee.getFacultyByCommitteeMember1().getFacultyId()));
    			thesis.setCommitteeMember1Name(thesisCommittee.getFacultyByCommitteeMember1().getFullName());
    		
    		}
    		
    		if(thesisCommittee.getFacultyByCommitteeMember2()!=null){
    			thesis.setCommitteeMember2Id(Integer.toString(thesisCommittee.getFacultyByCommitteeMember2().getFacultyId()));
    			thesis.setCommitteeMember2Name(thesisCommittee.getFacultyByCommitteeMember2().getFullName());
    		
    		}
    		
    		if(thesisCommittee.getFacultyByCommitteeMember3()!=null){
    			thesis.setCommitteeMember3Id(Integer.toString(thesisCommittee.getFacultyByCommitteeMember3().getFacultyId()));
    			thesis.setCommitteeMember3Name(thesisCommittee.getFacultyByCommitteeMember3().getFullName());
    		
    		}
    		
    		if(thesisCommittee.getFacultyByCommitteeMember4()!=null){
    			thesis.setCommitteeMember4Id(Integer.toString(thesisCommittee.getFacultyByCommitteeMember4().getFacultyId()));
    			thesis.setCommitteeMember4Name(thesisCommittee.getFacultyByCommitteeMember4().getFullName());
    		
    		}
    		
    	}
    	
    	
    	Set<ThesisToThesisStatus> thesisToThesisStatuses = thesis.getThesisToThesisStatuses();
    	for(ThesisToThesisStatus status:thesisToThesisStatuses)
		{
			
			System.out.println("ThesisController.viewExistingThesis()======status.getThesisStatus().getProspectusPassed()========"+status.getThesisStatus().getProspectusPassed());
			//enrolled details
			thesis.setEnrolledDateStr(status.getThesisStatus().getEnrolledDate()!=null?DateUtil.dateToStr(status.getThesisStatus().getEnrolledDate()):"");
			thesis.setEnrolled(status.getThesisStatus().getEnrolled());
			
			//prospectus details
			thesis.setProspectusDateStr(status.getThesisStatus().getProspectusDate()!=null?DateUtil.dateToStr(status.getThesisStatus().getProspectusDate()):"");
			thesis.setProspectusPassed(status.getThesisStatus().getProspectusPassed());
			// defense details
			thesis.setDefenseDateStr(status.getThesisStatus().getDefenseDate()!=null?DateUtil.dateToStr(status.getThesisStatus().getDefenseDate()):"");
			thesis.setDefensePassed(status.getThesisStatus().getDefensePassed());
			//Submitted/Accepted SoC Details
			thesis.setSubmittedSoC(status.getThesisStatus().getSubmittedSoC());
			thesis.setSubSoCDateStr(status.getThesisStatus().getSubmittedSoCdate()!=null?DateUtil.dateToStr(status.getThesisStatus().getSubmittedSoCdate()):"");
			thesis.setAcpSoCDateStr(status.getThesisStatus().getAcceptedSoCdate()!=null?DateUtil.dateToStr(status.getThesisStatus().getAcceptedSoCdate()):"");
			//Submitted/Accepted Director Details
			thesis.setSubmittedDirector(status.getThesisStatus().getSubmittedDirector());
			thesis.setSubDirDateStr(status.getThesisStatus().getSubmittedDirectorDate()!=null?DateUtil.dateToStr(status.getThesisStatus().getSubmittedDirectorDate()):"");
			thesis.setAcpDirDateStr(status.getThesisStatus().getAcceptedDirectorDate()!=null?DateUtil.dateToStr(status.getThesisStatus().getAcceptedDirectorDate()):"");
			//Submitted/Accepted Dean Details
			thesis.setSubmittedDean(status.getThesisStatus().getSubmittedDean());
			thesis.setSubDeanDateStr(status.getThesisStatus().getSubmittedDeanDate()!=null?DateUtil.dateToStr(status.getThesisStatus().getSubmittedDeanDate()):"");
			thesis.setAcpDeanDateStr(status.getThesisStatus().getAcceptedDeanDate()!=null?DateUtil.dateToStr(status.getThesisStatus().getAcceptedDeanDate()):"");
			//Submitted/Accepted Grad Dean Details
			thesis.setSubmittedGradDean(status.getThesisStatus().getSubmittedGradDean());
			thesis.setSubGradDeanDateStr(status.getThesisStatus().getSubmittedGradDeanDate()!=null?DateUtil.dateToStr(status.getThesisStatus().getSubmittedGradDeanDate()):"");
			thesis.setAcpGradDeanDateStr(status.getThesisStatus().getAcceptedGradDeanDate()!=null?DateUtil.dateToStr(status.getThesisStatus().getAcceptedGradDeanDate()):"");
			//Submitted/Accepted Library Details
			thesis.setSubmittedLibrary(status.getThesisStatus().getSubmittedLibrary());
			thesis.setSubLibraryDateStr(status.getThesisStatus().getSubmittedLibraryDate()!=null?DateUtil.dateToStr(status.getThesisStatus().getSubmittedLibraryDate()):"");
			thesis.setAcpLibraryDateStr(status.getThesisStatus().getAcceptedLibraryDate()!=null?DateUtil.dateToStr(status.getThesisStatus().getAcceptedLibraryDate()):"");
		
			thesis.setComments(status.getThesisStatus().getComments());
		}
 		model.addAttribute("studentList", studentMap);
		thesis.setCategoryStr(thesis.getCategory().getCategoryName());
		
		//thesis.setThesisChairId(thesisChairId)
    	model.addAttribute("thesis",thesis);
		return RMSConstants.ADD_THESIS_VIEW;
	}
    
    
    @RequestMapping(value = "/updateThesis", method = RequestMethod.POST)
	public String updateThesis(@RequestParam(required=true) int thesisId,@ModelAttribute("thesis") Thesis thesis,BindingResult bindingResult,Model model) {
    	
    	//Fetch the original thesis to be editted
    	Thesis existingThesis = thesisService.getThesisById(thesisId);
    	
    	//setting the Thesis Fields
    	Category category = existingThesis.getCategory();
    	category.setCategoryId(new Integer(thesis.getCategoryStr()));
    	existingThesis.setCategory(category);
    	
    	existingThesis.setStudent(thesis.getStudent());
    	existingThesis.setTitle(String.valueOf(thesis.getTitle()));
    	existingThesis.setAbstract_(thesis.getAbstract_());
    	existingThesis.setThesisDoi(thesis.getThesisDoi());
    	
    	//Edit the Thesis Committee
		Set<ThesisCommittee> exitingThesisCommittees = existingThesis.getThesisCommittees();
        
        System.out.println("ThesisController.updateThesis()=========before for loop========="+exitingThesisCommittees.size());
        
    	for(ThesisCommittee existingThesisCommittee:exitingThesisCommittees)
    	{
    		List<Faculty> facultyList = facultyService.getFacultyList();
    		int facultyChairInt = -1, facultyMember1Int = -1, facultyMember2Int = -1, facultyMember3Int = -1, facultyMember4Int = -1;
    		Faculty facultyChair = null, facultyMember1 = null, facultyMember2 = null, facultyMember3 = null, facultyMember4 = null;
    		
    		
    		if(thesis.getThesisChairId()!=null && thesis.getThesisChairId().length()>0){
    			facultyChairInt = new Integer(thesis.getThesisChairId());
    		}
    		if(thesis.getCommitteeMember1Id()!=null && thesis.getCommitteeMember1Id().length()>0){
    			facultyMember1Int = new Integer(thesis.getCommitteeMember1Id());
    		}
    		if(thesis.getCommitteeMember2Id()!=null && thesis.getCommitteeMember2Id().length()>0){
    			facultyMember2Int = new Integer(thesis.getCommitteeMember2Id());
    		}
    		if(thesis.getCommitteeMember3Id()!=null && thesis.getCommitteeMember3Id().length()>0){
    			facultyMember3Int = new Integer(thesis.getCommitteeMember3Id());

    		}
    		if(thesis.getCommitteeMember4Id()!=null && thesis.getCommitteeMember4Id().length()>0){
    			facultyMember4Int = new Integer(thesis.getCommitteeMember4Id());
    		}
    		
    		for(Faculty faculty:facultyList){
    			if(facultyChairInt == faculty.getFacultyId()){
    				facultyChair = faculty;
    			}
    			if(facultyMember1Int == faculty.getFacultyId()){
    				facultyMember1 = faculty;
    			}
    			if(facultyMember2Int == faculty.getFacultyId()){
    				facultyMember2 = faculty;
    			}
    			if(facultyMember3Int == faculty.getFacultyId()){
    				facultyMember3 = faculty;
    			}
    			if(facultyMember4Int == faculty.getFacultyId()){
    				facultyMember4 = faculty;
    			}
    		}
    		
    		existingThesisCommittee.setFacultyByCommitteeChair(facultyChair);
    		existingThesisCommittee.setFacultyByCommitteeMember1(facultyMember1);
    		existingThesisCommittee.setFacultyByCommitteeMember2(facultyMember2);
    		existingThesisCommittee.setFacultyByCommitteeMember3(facultyMember3);
    		existingThesisCommittee.setFacultyByCommitteeMember4(facultyMember4);
    		
    		existingThesisCommittee.setThesis(existingThesis);
    		
    	}
		existingThesis.setThesisCommittees(exitingThesisCommittees);
    	
    	//Edit the Thesis Status
    	Set<ThesisToThesisStatus> existingThesisToThesisStatuses = existingThesis.getThesisToThesisStatuses();
    	
    	for(ThesisToThesisStatus existingStatus:existingThesisToThesisStatuses)
		{
    		
			System.out.println("ThesisController.viewExistingThesis()======status.getThesisStatus().getProspectusPassed()========"+existingStatus.getThesisStatus().getProspectusPassed());
			
			//set flags
			existingStatus.getThesisStatus().setEnrolled(String.valueOf(thesis.getEnrolled()));
			existingStatus.getThesisStatus().setProspectusPassed(String.valueOf(thesis.getProspectusPassed()));
			existingStatus.getThesisStatus().setDefensePassed(String.valueOf(thesis.getDefensePassed()));
			existingStatus.getThesisStatus().setSubmittedSoC(String.valueOf(thesis.getSubmittedSoC()));
			existingStatus.getThesisStatus().setSubmittedDirector(String.valueOf(thesis.getSubmittedDirector()));
			existingStatus.getThesisStatus().setSubmittedDean(String.valueOf(thesis.getSubmittedDean()));
			existingStatus.getThesisStatus().setSubmittedGradDean(String.valueOf(thesis.getSubmittedGradDean()));
			existingStatus.getThesisStatus().setSubmittedLibrary(String.valueOf(thesis.getSubmittedLibrary()));
			
			//enrolled details
			if(thesis.getEnrolledDateStr()!=null && thesis.getEnrolledDateStr().length() > 0)
				existingStatus.getThesisStatus().setEnrolledDate(DateUtil.strToDate(thesis.getEnrolledDateStr()));
			//prospectus details
			if(thesis.getProspectusDateStr()!=null && thesis.getProspectusDateStr().length() > 0)
				existingStatus.getThesisStatus().setProspectusDate(DateUtil.strToDate(thesis.getProspectusDateStr()));
			//defense details
			if(thesis.getDefenseDateStr()!=null && thesis.getDefenseDateStr().length() > 0)
				existingStatus.getThesisStatus().setDefenseDate(DateUtil.strToDate(thesis.getDefenseDateStr()));
			
			//SoC Details
			if(thesis.getSubSoCDateStr()!=null && thesis.getSubSoCDateStr().length() > 0)
				existingStatus.getThesisStatus().setSubmittedSoCdate(DateUtil.strToDate(thesis.getSubSoCDateStr()));
			if(thesis.getAcpSoCDateStr()!=null && thesis.getAcpSoCDateStr().length() > 0)
				existingStatus.getThesisStatus().setAcceptedSoCdate(DateUtil.strToDate(thesis.getAcpSoCDateStr()));
			
			//SoC Director Details
			if(thesis.getSubDirDateStr()!=null && thesis.getSubDirDateStr().length() > 0)
				existingStatus.getThesisStatus().setSubmittedDirectorDate(DateUtil.strToDate(thesis.getSubDirDateStr()));
			if(thesis.getAcpDirDateStr()!=null && thesis.getAcpDirDateStr().length() > 0)
				existingStatus.getThesisStatus().setAcceptedDirectorDate(DateUtil.strToDate(thesis.getAcpDirDateStr()));
			
			//CCEC Dean Details
			if(thesis.getSubDeanDateStr()!=null && thesis.getSubDeanDateStr().length() > 0)
				existingStatus.getThesisStatus().setSubmittedDeanDate(DateUtil.strToDate(thesis.getSubDeanDateStr()));
			if(thesis.getAcpDeanDateStr()!=null && thesis.getAcpDeanDateStr().length() > 0)
				existingStatus.getThesisStatus().setAcceptedDeanDate(DateUtil.strToDate(thesis.getAcpDeanDateStr()));
			
			//Graduate Dean Details
			if(thesis.getSubGradDeanDateStr()!=null && thesis.getSubGradDeanDateStr().length() > 0)
				existingStatus.getThesisStatus().setSubmittedGradDeanDate(DateUtil.strToDate(thesis.getSubGradDeanDateStr()));
			if(thesis.getAcpGradDeanDateStr()!=null && thesis.getAcpGradDeanDateStr().length() > 0)
				existingStatus.getThesisStatus().setAcceptedGradDeanDate(DateUtil.strToDate(thesis.getAcpGradDeanDateStr()));
			
			//Library Details
			if(thesis.getSubLibraryDateStr()!=null && thesis.getSubLibraryDateStr().length() > 0)
				existingStatus.getThesisStatus().setSubmittedLibraryDate(DateUtil.strToDate(thesis.getSubLibraryDateStr()));
			if(thesis.getAcpLibraryDateStr()!=null && thesis.getAcpLibraryDateStr().length() > 0)
				existingStatus.getThesisStatus().setAcceptedLibraryDate(DateUtil.strToDate(thesis.getAcpLibraryDateStr()));
			
			existingStatus.getThesisStatus().setComments(thesis.getComments());
			
			existingStatus.setThesis(existingThesis);
		}

		existingThesis.setThesisToThesisStatuses(existingThesisToThesisStatuses);
    	
		//Update Existing Thesis
		thesisService.updateThesis(existingThesis);
		
		return "redirect:viewThesisList.html";
	}
        
	/**
	 * This populates the thesis data
	 * @param thesis
	 */
	private void populateThesisData(Thesis thesis)
	{
		System.out.println("ThesisController.populateThesisData()========="+thesis);
		Set<ThesisCommittee> thesisCommittees = new HashSet<ThesisCommittee>();
		ThesisCommittee thesisCommittee = new ThesisCommittee();
		List<Faculty> facultyList = facultyService.getFacultyList();
		int facultyChairInt = -1, facultyMember1Int = -1, facultyMember2Int = -1, facultyMember3Int = -1, facultyMember4Int = -1;
		Faculty facultyChair = null, facultyMember1 = null, facultyMember2 = null, facultyMember3 = null, facultyMember4 = null;
		
		
		if(thesis.getThesisChairId()!=null && thesis.getThesisChairId().length()>0){
			facultyChairInt = new Integer(thesis.getThesisChairId());
		}
		if(thesis.getCommitteeMember1Id()!=null && thesis.getCommitteeMember1Id().length()>0){
			facultyMember1Int = new Integer(thesis.getCommitteeMember1Id());
		}
		if(thesis.getCommitteeMember2Id()!=null && thesis.getCommitteeMember2Id().length()>0){
			facultyMember2Int = new Integer(thesis.getCommitteeMember2Id());
		}
		if(thesis.getCommitteeMember3Id()!=null && thesis.getCommitteeMember3Id().length()>0){
			facultyMember3Int = new Integer(thesis.getCommitteeMember3Id());

		}
		if(thesis.getCommitteeMember4Id()!=null && thesis.getCommitteeMember4Id().length()>0){
			facultyMember4Int = new Integer(thesis.getCommitteeMember4Id());
		}
		
		for(Faculty faculty:facultyList){
			if(facultyChairInt == faculty.getFacultyId()){
				facultyChair = faculty;
			}
			if(facultyMember1Int == faculty.getFacultyId()){
				facultyMember1 = faculty;
			}
			if(facultyMember2Int == faculty.getFacultyId()){
				facultyMember2 = faculty;
			}
			if(facultyMember3Int == faculty.getFacultyId()){
				facultyMember3 = faculty;
			}
			if(facultyMember4Int == faculty.getFacultyId()){
				facultyMember4 = faculty;
			}
		}
		
		thesisCommittee.setFacultyByCommitteeChair(facultyChair);
		thesisCommittee.setFacultyByCommitteeMember1(facultyMember1);
		thesisCommittee.setFacultyByCommitteeMember2(facultyMember2);
		thesisCommittee.setFacultyByCommitteeMember3(facultyMember3);
		thesisCommittee.setFacultyByCommitteeMember4(facultyMember4);
		
		
		thesisCommittee.setThesis(thesis);
		thesisCommittees.add(thesisCommittee);
		thesis.setThesisCommittees(thesisCommittees);
		
		Set<ThesisToThesisStatus> thesisToThesisStatuses = new HashSet<ThesisToThesisStatus>();
		ThesisStatus thesisStatus = new ThesisStatus(thesis.getEnrolled(), thesis.getEnrolledDate(),
				thesis.getProspectusPassed(), thesis.getProspectusDate(),  thesis.getDefensePassed(), thesis.getDefenseDate(),
				thesis.getSubmittedSoC(), thesis.getSubmittedSoCdate(), thesis.getAcceptedSoCdate(),
				thesis.getSubmittedDirector(), thesis.getSubmittedDirectorDate(), thesis.getAcceptedDirectorDate(),
				thesis.getSubmittedDean(), thesis.getSubmittedDeanDate(), thesis.getAcceptedDeanDate(),
				thesis.getSubmittedGradDean(), thesis.getSubmittedGradDeanDate(), thesis.getAcceptedGradDeanDate(),
				thesis.getSubmittedLibrary(), thesis.getSubmittedLibraryDate(), thesis.getAcceptedLibraryDate(),
				thesis.getComments(), 
				thesisToThesisStatuses);
		ThesisToThesisStatus thesisToThesisStatus = new ThesisToThesisStatus(thesisStatus,thesis);
		thesisToThesisStatuses.add(thesisToThesisStatus);
		thesis.setThesisToThesisStatuses(thesisToThesisStatuses);
	}
	
}
